package com.appheader.rongmaphone.utils.network;

import com.appheader.rongmaphone.constants.GlobalVars;

import java.util.HashMap;

import okhttp3.Callback;
import okhttp3.OkHttpClient;

/**
 * Created by zhep on 2016/10/9.
 */
public class HttpUtil {
    private static final String TAG = "httputils";

    private static final OkHttpClient okHttpClient = new OkHttpClient();
    static String pathString = null;
    private static String result;

    public HttpUtil() {
        // TODO Auto-generated constructor stub
    }

    public static void getLoginOkHttpClient(String path,String name, String password,Callback callback){
        HashMap<String, String> params = new HashMap<>();
        params.put("loginName", name);
        params.put("password", password);
//        Request request = new Request.Builder().url(path).build();

        okHttpClient.newCall(HttpHeader.getHeaderRequest(path, params)).enqueue(callback);
    }

    public static void getCloudOkHttpClient(Callback callback){
        HashMap<String, String> params = new HashMap<>();
        params.put("pageType", "phone");
        okHttpClient.newCall(HttpHeader.getHeaderRequest(GlobalVars.getAppCloudUrl(),params)).enqueue(callback);
    }

    public static void getCloudSuggestOkHttpClient(Callback callback,String suggestion){
        HashMap<String,String> params = new HashMap<>();
        params.put("content",suggestion);
        okHttpClient.newCall(HttpHeader.getHeaderRequest(GlobalVars.getSuggestionUrl(),params)).enqueue(callback);
    }
    public static void getCloudContentOkHttpClient(Callback callback,String projectId,String md5,String lastModifyTime){

        HashMap<String ,String> params = new HashMap<>();
        params.put("projectId",projectId);
        params.put("lastModifyTime",lastModifyTime);
        params.put("md5",md5);

        okHttpClient.newCall(HttpHeader.getHeaderRequest(GlobalVars.getAppContentCloudUrl(),params)).enqueue(callback);
    }

    public static void getCloudUserListOkHttpClient(Callback callback){
        okHttpClient.newCall(HttpHeader.getHeaderRequest(GlobalVars.getAppCloudUserListUrl(),null)).enqueue(callback);
    }
    //zip包下载get请求
    public static void getZipOkHttpClient(Callback callback){
        okHttpClient.newCall(HttpHeader.getHeaderZipRequest(GlobalVars.getAppZipUrl())).enqueue(callback);
    }
    //用户退出登录请求
    public static void getUserLogOutOkHttpClient(Callback callback){
        okHttpClient.newCall(HttpHeader.getHeaderRequest(GlobalVars.getAppLogOut(),null)).enqueue(callback);
    }

    //每一页请求
    public static void getPageOkHttpClient(Callback callback,String pageId,String lastModifyTime){
        HashMap<String ,String> params = new HashMap<>();
        params.put("id",pageId);
        params.put("lastModifyTime",lastModifyTime);
        okHttpClient.newCall(HttpHeader.getHeaderRequest(GlobalVars.getAppContentPageUrl(),params)).enqueue(callback);
    }

}
